package Solutions;

public class Solution10 {
    public static void main(String[] args) {
        System.out.println(new solution010().removeDuplicates(new int[]{1,1,2,2,2,3,4}));
    }
}

class solution010 {
    public int removeDuplicates(int[] nums) {
        //双指针
        int left=0;
        int right=1;
        //先判断数组是否为空
        if (nums==null)return 0;
        while (right<nums.length){
            if (nums[right]==nums[left]){
                //若相等则右侧指针加1直到与左指针不等
                right++;
            }else {
                //左右不相等，让不重复的数字移动到左指针右侧，两个指针右移一位
                nums[left+1]=nums[right];
                left++;
                right++;
            }
        }
        return left+1;
    }
}
